
/************************************************************************/
/*    Author: Scott Bevin                                               */
/************************************************************************/

#pragma once

#include "QuadTreeNode.h"

namespace XF
{
	class QuadTree
	{
	private:
		QuadTreeNode *mRootNode;
		Ogre::SceneNode* mManObjNode;
		bool mRenderingTree;
		Ogre::SceneManager *mOgreManager;

		void AddTreeToOgre();

	public:
		QuadTree(float x, float y, float w, float h, unsigned int targetObjects, unsigned int maxDepth);
		~QuadTree();

		/**
		this function will add an object into the tree, subdividing if necessary and possible
		*/
		bool AddBody(Body* body){ return mRootNode->AddBody(body); }

		/**
		remove object will remove an object and unnecessary nodes
		*/
		bool RemoveBody(Body* body){ return mRootNode->RemoveBody(body);}

		//QuadTreeNode* Root(){ return mRootNode; }
		int TargetObjects(){ return mRootNode->TargetObjects(); }
		int MaxDepth(){ return mRootNode->MaxDepth(); }

		int ObjectsInTree(){ return mRootNode->GetNoOfObjects(); }

		void RenderTreeInCout(){ mRootNode->RenderNodeInCout(); }

		void Update(double dT);

		void RenderTree(Ogre::SceneManager *manager){mRenderingTree = true; mOgreManager = manager;}
		void StopRenderingTree(){mRenderingTree = false;}
		bool RenderingTree(){return mRenderingTree;}
	};
}